package drawing

/**
* Created by IntelliJ IDEA.
* User: koeppelad
* Date: 4/14/11
* Time: 8:29 PM
* To change this template use File | Settings | File Templates.
*/

import org.lwjgl.opengl.GL11._
import org.lwjgl.opengl.Display
import java.util.Stack
import scala.collection.mutable.ListBuffer
import org.lwjgl.util.Color

class HackedExampleDrawer{

  glColor3d(0.0,1.0,0.0);

  private var max = 0f;

  private val stack = new Stack[PositionAndOrientation]()
  private var width : Int = 0
  private var red :Float = 1f;
  private var blue : Float = 1f
  private var green : Float = 0f
  private var color : Unit = glColor3f(red, green, blue)
  private var increment = 0.03f


  private var positionAndOrientation: PositionAndOrientation =
  {
    val displayMode = Display.getDisplayMode
    val x = 0//displayMode.getWidth() / 2.0
    val y = 0//displayMode.getHeight() / 2.0
    val z = 0.0
    val pao = new PositionAndOrientation()
    pao.translate(x, y, z)
    pao
  }

  def x: Float = return positionAndOrientation.x
  def y: Float = return positionAndOrientation.y
  def z: Float = return positionAndOrientation.z

  def getMax: Float = return max

  def push(): Unit =
    stack.push(new PositionAndOrientation(positionAndOrientation))

  def pop(): Unit =
  {
    positionAndOrientation = stack.peek()
    stack.pop()
  }

  def getWidth = width
  def incrementWidth = width += 1
  def decrementWidth = if (width > 1) width -= 1

  def changeIncrement(newIncrement:Float) = {increment = newIncrement}

  def getColor() = glColor3f(red, green, blue)
  def incBlue = {blue += increment; if (blue >= 1) blue = 0f; getColor}
  def decBlue = {blue -= increment; if (blue <= 0) blue = 1f; getColor}
  def incGreen = {green += increment; if (green >= 1) green = 0f; getColor}
  def decGreen = {green -= increment; if (green <= 0) green = 1f; getColor}
  def incRed = {red += increment; if (red >= 1) red = 0f; getColor}
  def decRed = {red -= increment; if (red <= 0) red = 1; getColor}


  def draw(distance: Double)
  {
    glVertex3d(x, y, z)
    move(distance)
  }

  def turnAround() : Unit = turnLeft(math.Pi / 2)

  def checkMaxes(){
    if (max < positionAndOrientation.x) max = positionAndOrientation.x
    if (max < positionAndOrientation.y) max = positionAndOrientation.y
    if (max < positionAndOrientation.z) max = positionAndOrientation.z
    getColor
    glLineWidth(width)
  }

  def move[N : Numeric](distance: N): Unit = {
    positionAndOrientation.translate(distance, 0, 0)
    checkMaxes
  }
  def turnLeft[N : Numeric](angle: N): Unit = {
    positionAndOrientation.rotateZ(angle)
    checkMaxes
  }

  def turnRight[N](angle: N)(implicit numeric : Numeric[N]): Unit = {
    positionAndOrientation.rotateZ(numeric.negate(angle))
    checkMaxes
  }

  def pitchUp[N : Numeric](angle: N): Unit = {
    positionAndOrientation.rotateY(angle)
    checkMaxes
  }

  def pitchDown[N](angle: N)(implicit numeric : Numeric[N]): Unit = {
    positionAndOrientation.rotateY(numeric.negate(angle))
    checkMaxes
  }

  def rollLeft[N : Numeric](angle: N): Unit = {
    positionAndOrientation.rotateX(angle)
    checkMaxes
  }

  def rollRight[N](angle: N)(implicit numeric : Numeric[N]): Unit = {
    positionAndOrientation.rotateX(numeric.negate(angle))
    checkMaxes
  }
}